package com.downloading.bezoyaapp.lists;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.downloading.bezoyaapp.R;

import downloading.fragmentos.URLtoDrawable.UrlImageViewHelper;

public class ListWithPictureAdapter extends BaseAdapter {

	private ArrayList _data;
	Context _c;

	public ListWithPictureAdapter(ArrayList data, Context c) {
		_data = data;
		_c = c;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return _data.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return _data.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		NameYFotoListItem msg = (NameYFotoListItem) _data.get(position);

		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) _c
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.preguntarespuesta_list_item, null);
			v.setTag(msg.getId());

		}

		TextView text = (TextView) v.findViewById(R.id.pregunta);
		ImageView image = (ImageView) v.findViewById(R.id.conrespuesta);
		text.setText(msg.getName());
		UrlImageViewHelper.setUrlDrawable(image, msg.getFoto());

		return v;
	}
}
